package orm;

public class SqlPool {
    private   ConnectionProxy[] connProxies = new ConnectionProxy[Dbconf.getIntagerValue("minPoolSize","1")];

    private static byte [] connProxyBitMap = new byte [Dbconf.getIntagerValue("minPoolSize","1")];

    private  int total=0;
    private byte busy=1;
    private static byte free=0;
    private static byte no_available =-1;
    private static byte no_null =-2;

    static {
        for (int i = 0; i < connProxyBitMap.length; i++) {
            connProxyBitMap[i]=no_available;
        }
    }

    private static int getFreeIdx(){
        return getIdx(free, no_available);
    }
    private static int getNullIdx(){

        return getIdx(no_available, no_null);
    }

    private static int getIdx(byte tar, byte no_free) {
        for (int i = 0; i < connProxyBitMap.length; i++) {
            if (connProxyBitMap[i]== tar){
                return i;
            }
        }
        return no_free;
    }

    private int grow(){
        ConnectionProxy[] conn = new ConnectionProxy[connProxies.length*2];
        byte[] connBitMap = new byte[connProxyBitMap.length*2];
        System.arraycopy(connProxies,0,conn,0,connProxies.length);
        System.arraycopy(connProxyBitMap,0,connBitMap,0,connProxyBitMap.length);
        int firstNull = connProxies.length;
        connProxies =conn;
        connProxyBitMap =connBitMap;
        for (int i = firstNull; i < firstNull*2; i++) {
            connProxyBitMap[i]=no_available;
        }
        return firstNull;
    }

    private ConnectionProxy distribute(int idx){
        if (connProxyBitMap[idx]==busy){
            return null;
        }
        ConnectionProxy cp= null;
        if (connProxyBitMap[idx]==no_available){
            cp = new ConnectionProxy
            return null;
        }

    }
}
